package cn.blunce.utils.ScreenHelper;

import android.app.Activity;
import android.util.DisplayMetrics;

/**
 * 获取设备的分辨率，屏幕密度等相关参数
 * <p/>
 * 与无标题和全屏幕配合使用：
 * 找到父布局设置属性：content.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
 * Created by Blunce on 2015/11/1 0001.
 */
public class GetUISize {

    /**
     * 屏幕宽度，单位：px
     */
    private int screenWidth;

    /**
     * 屏幕高度，单位：px
     */
    private int screenHeight;


    /**
     * the quantity of pixels within a physical area of the screen
     * 像素密度，每单位像素数量，单位：dpi
     */

    private int pixelDesity;

    /**
     * 1dp = ? px
     */
    private float dpPerPixel;

    /**
     * 1px = ? dp
     */
    private float pixelPerDp;

    /**
     * 放大像素，用于显示字体
     */
    private float pixelMagnify;

    /**
     * 1sp = ? px
     */
    private float spPerPixel;

    /**
     * 1px = ? sp
     */
    private float pixelPerSp;

    public GetUISize(Activity activity) {
        DisplayMetrics dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        screenWidth = dm.widthPixels;
        screenHeight = dm.heightPixels;
        pixelDesity = dm.densityDpi;
        pixelMagnify = dm.scaledDensity;

        dpPerPixel = 160f / pixelDesity;
        pixelPerDp = pixelDesity / 160f;

        spPerPixel = pixelMagnify;
        pixelPerSp = 1f / pixelMagnify;
    }

    public int getScreenWidth() {
        return screenWidth;
    }

    public int getScreenHeight() {
        return screenHeight;
    }

    public int getPixelDesity() {
        return pixelDesity;
    }

    public float getDpPerPixel() {
        return dpPerPixel;
    }

    public float getPixelPerDp() {
        return pixelPerDp;
    }

    public float getPixelMagnify() {
        return pixelMagnify;
    }

    public float getSpPerPixel() {
        return spPerPixel;
    }

    public float getPixelPerSp() {
        return pixelPerSp;
    }
}
